import axios from 'axios'
import {
  baseUrl,
  port
} from './propty'
let http = axios.create({
  baseURL: `${baseUrl}:${port}`,
  timeout: 10000
})

export default {
  get(url, params) {
    return new Promise((resolve, reject) => {
      http.get(url, {
        params
      }).then(data => {
        resolve(data)
      }).catch(err => {
        if (err.response) {
          resolve(err.response.data)
        } else {
          reject(err)
        }
      })
    })
  },
  post(url, params) {
    return new Promise((resolve, reject) => {
      http.post(url, params).then(data => {
        resolve(data)
      }).catch(err => {
        if (err.response) {
          resolve(err.response.data)
        } else {
          reject(err)
        }
      })
    })
  }
}